CLASS lhc_menu DEFINITION INHERITING FROM cl_abap_behavior_handler.

  PRIVATE SECTION.

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR menu RESULT result.
    METHODS precheck_delete FOR PRECHECK
      IMPORTING keys FOR DELETE menu.

ENDCLASS.

CLASS lhc_menu IMPLEMENTATION.

  METHOD get_instance_authorizations.
  ENDMETHOD.

  METHOD precheck_delete.
    READ ENTITIES OF ymoon_r_form IN LOCAL MODE
      ENTITY form
      ALL FIELDS WITH
      CORRESPONDING #( keys )
      RESULT DATA(lt_result)
      ENTITY form BY \_menu
      ALL FIELDS WITH
      CORRESPONDING #( keys )
      RESULT DATA(lt_result_menu)
      FAILED DATA(lt_failed)
      .

    LOOP AT keys ASSIGNING FIELD-SYMBOL(<entity>).
      READ TABLE lt_result ASSIGNING FIELD-SYMBOL(<fs_form>) WITH KEY formid = <entity>-formid.
      READ TABLE lt_result_menu ASSIGNING FIELD-SYMBOL(<fs_menu>) WITH KEY parentmenu = <entity>-menuid.
      IF sy-subrc = 0.
        APPEND VALUE #(     %tky         = <fs_form>-%tky
                            %delete      = if_abap_behv=>mk-on
                            %update      = if_abap_behv=>mk-off
                            %fail-cause  = if_abap_behv=>cause-conflict
                          )
                      TO failed-form.

        APPEND VALUE #( %msg      = new_message_with_text(
                                        severity  = if_abap_behv_message=>severity-warning
                                        text      = <entity>-menuid && ': Sub메뉴가 있는 항목은 삭제불가합니다.' )
                       %delete = if_abap_behv=>mk-on
                       %tky      = <fs_form>-%tky )

                     TO reported-form.
      ENDIF.

    ENDLOOP.







  ENDMETHOD.

ENDCLASS.

CLASS lhc_form DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.



    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR form RESULT result.
    METHODS precheck_delete FOR PRECHECK
      IMPORTING keys FOR DELETE form.
    METHODS statuscheck FOR MODIFY
      IMPORTING keys FOR ACTION form~statuscheck RESULT result.

ENDCLASS.

CLASS lhc_form IMPLEMENTATION.

  METHOD get_instance_authorizations.
  ENDMETHOD.

  METHOD precheck_delete.


    READ ENTITIES OF ymoon_r_form IN LOCAL MODE
    ENTITY form
    ALL FIELDS WITH
    CORRESPONDING #( keys )
    RESULT DATA(lt_result)
    ENTITY form BY \_menu
    ALL FIELDS WITH
    CORRESPONDING #( keys )
    RESULT DATA(lt_result_menu)
    FAILED DATA(lt_failed)
    .


    LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<entity>).
      READ TABLE lt_result_menu ASSIGNING FIELD-SYMBOL(<fs_menu>) WITH KEY formid = <entity>-formid.
      IF sy-subrc = 0.



        APPEND VALUE #( %msg      = new_message_with_text(
                     severity  = if_abap_behv_message=>severity-warning
                     text      = <entity>-formid && ': 메뉴가 있는 폼은 삭제불가합니다.' )
                     %tky      = <entity>-%tky
                     %delete      = if_abap_behv=>mk-on )
                     TO reported-form.

        APPEND VALUE #(     %tky         = <entity>-%tky
                    %delete      = if_abap_behv=>mk-on
                    %update      = if_abap_behv=>mk-off
                    %create      = if_abap_behv=>mk-off
                    %fail-cause  = if_abap_behv=>cause-unspecific

                  )
              TO failed-form.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.


  METHOD statuscheck.

    MODIFY ENTITIES OF ymoon_r_form IN LOCAL MODE
    ENTITY form
    UPDATE FROM VALUE #( FOR key IN keys ( %tky = key-%tky loekz = '1' %control-loekz = if_abap_behv=>mk-on ) )
    FAILED failed
    REPORTED reported.


    READ ENTITIES OF ymoon_r_form IN LOCAL MODE
    ENTITY form
    ALL FIELDS WITH
    CORRESPONDING #( keys )
    RESULT DATA(lt_result).

    LOOP AT keys ASSIGNING FIELD-SYMBOL(<key>).
      APPEND VALUE #( %msg      = new_message_with_text(
           severity  = if_abap_behv_message=>severity-warning
           text      = <key>-formid && ' 폼은 메뉴가 있는 항목입니다. 삭제하시겠습니까?' )
           %tky      = <key>-%tky )
           TO reported-form.

    ENDLOOP.


*    result = VALUE #( FOR ls_result IN lt_result ( %tky = ls_result-%tky %param = ls_result ) ).


  ENDMETHOD.

ENDCLASS.
